<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:insert="~{include :: header('课程列表')}" />
    <th:block th:insert="~{include :: bootstrap-table-css}" />
</head>
<body class="hold-transition">
<div class="container-fluid mb-2">
    <div class="toolbar" id="toolbar" role="group">
        <form id="formId" class="form-inline">
            <input class="form-control mr-1" placeholder="课程名称" type="text" name="courseName"/>
            <a class="btn btn-primary btn-rounded mr-1" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
            <a class="btn btn-warning btn-rounded" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
        </form>
    </div>
    <table id="bootstrap-table" class="table-striped"></table>
</div>
<th:block th:insert="~{include :: footer}" />
<th:block th:insert="~{include :: bootstrap-table-js}" />
<script th:inline="javascript">
    var isAvailableDatas = [[${@dict.getType('qdx_course_state')}]];
    var sellTypeDatas = [[${@dict.getType('qdx_course_type')}]];

    $(function() {
        var options = {
            url: "/user/course/list.json",
            showSearch: false,
            showRefresh: false,
            showToggle: false,
            showColumns: false,
            modalName: "课程",
            columns: [
                {
                    field: 'courseId',
                    title: 'id'
                },
                {
                    field: 'sellType',
                    title: '类别',
                    formatter: function (value, row, index) {
                        if (value === "COURSE") {
                            return $.table.selectDictLabel(sellTypeDatas, value);
                        } else if (value === "LIVE") {
                            return '<span style="color: #2798C8">' + $.table.selectDictLabel(sellTypeDatas, value) + '</span>'
                        } else if (value === "PACKAGE") {
                            return '<span style="color:red;">' + $.table.selectDictLabel(sellTypeDatas, value) + '</span>'
                        }

                    }
                },
                {
                    field: 'courseName',
                    title: '名称'
                },
                {
                    field: 'isAvailable',
                    title: '状态',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(isAvailableDatas, value);
                    }
                },
                {
                    field: 'categoryName',
                    title: '专业'
                },
                {
                    field: 'sourcePrice',
                    title: '原价',
                    formatter: function (value, row, index) {
                        return value/100;
                    }
                },
                {
                    field: 'price',
                    title: '优惠价',
                    formatter: function (value, row, index) {
                        return value/100;
                    }
                },
                {
                    field: 'addTime',
                    title: '创建时间'
                },
                {
                    field: 'expireDate',
                    title: '有效结束时间',
                    formatter: function (value, row, index) {
                        return value;
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-info  btn-xs" href="javascript:void(0)" onclick="toFreeCourse(\'' + row.courseId + '\')"><i class="fa fa-shopping-bag"></i> 赠送</a> ');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });

    //赠送课程操作
    function toFreeCourse(courseId) {
        var userId = [[${userId}]];
        $.modal.confirm("确定赠送课程吗?", function () {
            var data = {"userId": userId, "courseId": courseId};
            $.operate.submit("/user/course/free.json", "post", "json", data);
        });
    }
</script>
</body>
</html>